home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / telecomm / misc / xprzmodem.lha / Source / xprzmodem.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-14  |  9.2 KB  |  227 lines

  1. /*
  2.  *  xprzmodem.h: Definitions for xprzmodem.library;
  3.  *  Version 2.0, 28 October 1989, by Rick Huebner.
  4.  *  Released to the Public Domain; do as you like with this code.
  5.  */
  6.  
  7. /* #define DEBUGLOG 1 */
  8.  
  9. /* Return codes */
  10. #define OK        0
  11. #define ERROR   (-1)
  12. #define TIMEOUT (-2)
  13. #define RCDO    (-3)
  14.  
  15. /* Relevant control characters */
  16. #define CR    ('M' & 0x1F)    /* ^M */
  17. #define DLE    ('P' & 0x1F)    /* ^P */
  18. #define XON    ('Q' & 0x1F)    /* ^Q */
  19. #define XOFF    ('S' & 0x1F)    /* ^S */
  20. #define CAN    ('X' & 0x1F)    /* ^X */
  21. #define CPMEOF    ('Z' & 0x1F)    /* ^Z */
  22.  
  23. /* Misc. program constants */
  24. #define LZMANAG          0    /* Default ZMODEM file management mode */
  25. #define LZTRANS          0    /* Default ZMODEM file transport mode */
  26. #define PATHLEN        256    /* What's the max legal path size? */
  27. #define CONFIGLEN     32    /* Max length of transfer options string */
  28. #define KSIZE           1024    /* Max allowable packet size */
  29. #define MINBLOCK     64    /* Min allowable packet size */
  30. #define MAXGOODNEEDED  8192    /* Max # good bytes req'd to bump packet size */
  31.  
  32. /* Provision for future 7-bit ZMODEM; for now, there's no difference */
  33. #define sendline xsendline
  34.  
  35. /*
  36.  * Replacement for global variables normally used, in order to make code
  37.  * fully reentrant; each invocation allocs their own Vars, and passes the
  38.  * struct pointer down through the entire program so they're always available.
  39.  * Pointer to this struct is usually able to be a register variable, so access
  40.  * is no worse than any stack variable (all register-relative).  Kinda
  41.  * kludgey, but the original ZModem code design depended on lots of globals,
  42.  * and I didn't want to redesign the whole damn thing.  Besides, it's more
  43.  * efficient than constantly pushing & popping args all over the place.
  44.  */
  45.  
  46. struct Vars
  47. {
  48.   struct XPR_IO io;        /* Copy of XProto IO struct passed by term prog. */
  49.   struct XPR_UPDATE __aligned xpru;    /* Scratchpad xpr_update() control struct */
  50.   struct timeval __aligned Starttime;    /* Time transfer started */
  51.   UBYTE __aligned Rxhdr[4];    /* Received header */
  52.   UBYTE Txhdr[4];        /* Transmitted header */
  53.   UBYTE Msgbuf[128];        /* Scratchpad buffer for printing messages */
  54.   UBYTE Filename[PATHLEN];    /* Name of the file being up/downloaded */
  55.   UBYTE Pktbuf[KSIZE];        /* File data packet buffer */
  56.   UBYTE Modembuf[KSIZE * 4 + 256];    /* Input buffer for data from modem */
  57.   UBYTE Outbuf[KSIZE * 4 + 256];    /* Output buffer for data to modem */
  58.   UBYTE *Modemchar;        /* Next char to get from Modembuf */
  59.   UBYTE *Filebuf;        /* File I/O buffer address */
  60.   UBYTE *Filebufptr;        /* Current position within Filebuf */
  61.   ULONG Modtime;        /* Modification data. */
  62.   ULONG Bits;            /* Attribute bits. */
  63.   ULONG BytesSent;        /* How many bytes sent since last check. */
  64.   ULONG BytesReceived;        /* How many bytes received since last check. */
  65.   LONG Receiving;        /* Receiving or sending? */
  66.   long File;            /* Handle of file being transferred */
  67.   long Oldstatus;        /* Original terminal program's modem settings */
  68.   long Baud;            /* BPS setting of modem */
  69.   long Strtpos;            /* Starting byte position of transfer */
  70.   long Fsize;            /* Size of file being transferred */
  71.   long Rxbytes;            /* Number of bytes received so far */
  72.   long Filebufpos;        /* File offset of data in Filebuf */
  73.   long Filebufmax;        /* Size of Filebuf */
  74.   long Filebuflen;        /* Number of bytes currently stored in Filebuf */
  75.   long Filebufcnt;        /* Number of bytes remaining/written in Filebuf */
  76.   long Rxpos;            /* Received file position */
  77.   long Txpos;            /* Transmitted file position */
  78.   short Filcnt;            /* Number of files opened for transmission */
  79.   short Errcnt;            /* Number of files unreadable */
  80.   short Noroom;            /* Flags 'insufficient disk space' errors */
  81.   short Rxbuflen;        /* Largest frame they're willing to xfer */
  82.   short Tframlen;        /* Largest frame we're willing to xfer */
  83.   short Rxtimeout;        /* Tenths of seconds to wait for something */
  84.   short Tryzhdrtype;        /* Header type to send corresp to Last rx close */
  85.   short Modemcount;        /* Number of bytes available in Modembuf */
  86.   short Outbuflen;        /* Number of bytes currently stored in Outbuf */
  87.   short Rxframeind;        /* ZBIN or ZHEX; type of frame received */
  88.   short Txfcs32;        /* TRUE means send binary frame with 32 bit FCS */
  89.   short Rxflags;        /* Temp register */
  90.   short Wantfcs32;        /* want to send 32 bit FCS */
  91.   short Crc32t;            /* Display flag indicates 32 bit CRC being sent */
  92.   short Crc32;            /* Display flag indicates 32 bit CRC being recd */
  93.   short Rxtype;            /* Type of header received */
  94.   short Rxcount;        /* Count of data bytes received */
  95.   short Znulls;            /* Number of nulls to send at begin of ZDATA hdr */
  96.   short ErrorLimit;        /* How many sequential errors before abort */
  97.   short Zctlesc;        /* Are ctl chars to be escaped? */
  98.   short FileAttributes;        /* Bit 0: send file attributes, bit 1: honor file attributes received. */
  99.   char SetAttributes;        /* Set file attributes and time? */
  100.   char Rxbinary;        /* Force binary mode download? */
  101.   char Rxascii;            /* Force text mode download? */
  102.   char Thisbinary;        /* Receive this file in binary mode? */
  103.   char Lzconv;            /* Suggested binary/text mode for uploads */
  104.   char Eofseen;            /* Text-mode EOF marker (^Z) rec'd on download? */
  105.   UBYTE Zconv;            /* ZMODEM file conversion request */
  106.   UBYTE Zmanag;            /* ZMODEM file management request */
  107.   UBYTE Ztrans;            /* ZMODEM file transport request */
  108.   UBYTE Lastsent;        /* Last text char written by putsec() */
  109.   UBYTE Lastzsent;        /* Last char sent by zsendline() */
  110.   UBYTE Fileflush;        /* Flush file I/O buffer before closing? */
  111.   UBYTE Attn[ZATTNLEN + 1];    /* Attention string rx sends to tx on err */
  112.   LONG ksize;            /* Max allowable packet size */
  113. };
  114.  
  115. /*
  116.  * Option settings and other variables needed outside of XProtocolSend/Receive;
  117.  * separated from rest of Vars so that huge Vars struct doesn't have to be
  118.  * allocated except during transfers.  Pointer to this struct kept in xpr_data.
  119.  */
  120. struct SetupVars
  121. {
  122.   UBYTE *matchptr, *bufpos;
  123.   short buflen;
  124.   UBYTE option_t[2], option_o[2], option_b[8], option_f[8], option_e[8],
  125.     option_s[4];
  126.   UBYTE option_c[4], option_r[4], option_a[4], option_d[4], option_k[4],
  127.     option_p[256], option_m[8];
  128.   UBYTE option_i[2];
  129. };
  130.  
  131. /* Function prototypes */
  132.  
  133. long __saveds __asm XProtocolSend(register __a0 struct XPR_IO *xio);
  134. short getzrxinit(struct Vars *v);
  135. short sendzsinit(struct Vars *v);
  136. void sendbatch(struct Vars *v);
  137. short sendone(struct Vars *v);
  138. short sendname(struct Vars *v);
  139. short zsendfile(struct Vars *v, short blen);
  140. short zsendfdata(struct Vars *v);
  141. short getinsync(struct Vars *v);
  142. void saybibi(struct Vars *v);
  143.  
  144. long __saveds __asm XProtocolReceive(register __a0 struct XPR_IO *xio);
  145. short rcvbatch(struct Vars *v);
  146. short tryz(struct Vars *v);
  147. short rzfiles(struct Vars *v);
  148. short rzfile(struct Vars *v);
  149. short procheader(struct Vars *v);
  150. short putsec(struct Vars *v);
  151. void ackbibi(struct Vars *v);
  152.  
  153. long __saveds __asm XProtocolSetup(register __a0 struct XPR_IO *xio);
  154. long __saveds __asm XProtocolCleanup(register __a0 struct XPR_IO *xio);
  155. long __saveds __asm XProtocolHostMon(
  156.                       register __a0 struct XPR_IO *xio,
  157.                       register __a1 char *serbuff,
  158.                       register __d0 long actual,
  159.                       register __d1 long maxsize);
  160. long __saveds __asm XProtocolUserMon(
  161.                       register __a0 struct XPR_IO *xio,
  162.                       register __a1 char *serbuff,
  163.                       register __d0 long actual,
  164.                       register __d1 long maxsize);
  165. struct Vars *setup(struct XPR_IO *io);
  166. UBYTE *find_option(UBYTE * buf, UBYTE option);
  167. void set_textmode(struct Vars *v);
  168. void canit(struct Vars *v);
  169. void zmputs(struct Vars *v, UBYTE * s);
  170. void xsendline(struct Vars *v, UBYTE c);
  171. void sendbuf(struct Vars *v);
  172. short readock(struct Vars *v, short tenths);
  173. char char_avail(struct Vars *v);
  174. void update_rate(struct Vars *v);
  175. long bfopen(struct Vars *v, UBYTE * mode);
  176. void bfclose(struct Vars *v);
  177. void bfseek(struct Vars *v, long pos);
  178. long bfread(struct Vars *v, UBYTE * buf, long length);
  179. long bfwrite(struct Vars *v, UBYTE * buf, long length);
  180. void ioerr(struct XPR_IO *io, char *msg);
  181. void upderr(struct Vars *v, char *msg);
  182. void updmsg(struct Vars *v, char *msg);
  183. long getfree(struct Vars *v);
  184. char exist(struct Vars *v);
  185.  
  186. void __stdargs mysprintf(STRPTR, STRPTR,...);
  187. LONG Atol(STRPTR buffer);
  188. void __stdargs kprintf(STRPTR,...);
  189.  
  190. extern struct ExecBase *SysBase;
  191. extern struct DosLibrary *DOSBase;
  192. extern struct Library *UtilityBase;
  193. extern struct Library *TimerBase;
  194. extern LONG GMT_Offset;
  195.  
  196. void zsbhdr(struct Vars *v, USHORT type);
  197. void zshhdr(struct Vars *v, USHORT type);
  198. void zsdata(struct Vars *v, short length, USHORT frameend);
  199. short zrdata(struct Vars *v, UBYTE * buf, short length);
  200. short zrdat32(struct Vars *v, UBYTE * buf, short length);
  201. short zrdatr32(struct Vars *v, UBYTE * buf, short length);
  202. short zgethdr(struct Vars *v);
  203. short zrbhdr(struct Vars *v);
  204. short zrbhdr32(struct Vars *v);
  205. short zrhhdr(struct Vars *v);
  206. void zputhex(struct Vars *v, UBYTE c);
  207. void zsendline(struct Vars *v, UBYTE c);
  208. short zgethex(struct Vars *v);
  209. short zdlread(struct Vars *v);
  210. short noxrd7(struct Vars *v);
  211. void stohdr(struct Vars *v, long pos);
  212. long rclhdr(struct Vars *v);
  213.  
  214. STRPTR GetLocaleString(LONG);
  215.  
  216. /*
  217.  * # seconds between 1-1-70 (Unix time base) and 1-1-78 (Amiga time base).
  218.  * Add this value to the returned seconds count to convert Amiga system time
  219.  * to normal Unix system time.
  220.  */
  221.  
  222. #define UTC_OFFSET 252482400
  223.  
  224. ULONG getsystime(struct timeval *tv);
  225.  
  226. /* End of XprZmodem.h source */
  227.